<template>
  <div
    class="header"
    :style="{
      background: type !== 'home' ? '#fffff' : '',
      boxShadow:
        type !== 'home' ? '0rpx 4rpx 12rpx 0rpx rgba(205,207,210,0.27)' : '',
    }"
  >
    <div class="content">
      <img :src="type === 'home' ? logo : logo2" alt="" />
      <div class="left">
        <div class="orderbtn" @click="queryOrder">
          <img :src="type === 'home' ? order : order2" alt="" />
          <span :style="{ color: type === 'home' ? '#ffff' : '#252525' }"
            >我的订单</span
          >
        </div>
        <img :src="type === 'home' ? avatar : avatar2" alt="" />
      </div>
    </div>
  </div>
  <div
    class="bottom"
    :style="{
      background: type !== 'home' ? '#fffff' : '#000',
      boxShadow: type !== 'home' ? '0rpx -2rpx 0rpx 0rpx #ECEDED' : '',
    }"
  >
    <div class="content">
      <span :style="{ color: type !== 'home' ? '#252525' : '' }"
        >想动动⼝就能订机票？试试使⽤</span
      >
      <img src="../../static/img/siri.png" alt="" />
      <span
        :style="{ color: type !== 'home' ? '#050505' : '', fontWeight: 'bold' }"
        >Siri 预订机票</span
      >
    </div>
  </div>
  <van-popup v-model:show="showBottom" position="bottom" round>
    <div class="order-container">
      <div class="content">
        <div class="tab-container">
          <span class="title">我的订单</span>
          <div class="tab">
            <div
              class="tab-item"
              :class="{ active: activeIndex == index }"
              v-for="(item, index) in tabs"
              :key="index"
              @click="activeIndex = index"
            >
              <span>{{ item }}</span>
            </div>
          </div>
          <img
            class="closeimg"
            src="../../static/img/close.png"
            alt=""
            @click="closePop"
          />
        </div>
        <div class="body-container">
          <van-list
            v-model:loading="loading"
            :finished="finished"
            finished-text="没有更多了"
          >
            <TicketCard v-for="item in 10" />
          </van-list>
        </div>
      </div>
    </div>
  </van-popup>
</template>
<script setup lang="ts">
import logo from "@/static/img/logo.png";
import logo2 from "@/static/img/logo2.png";
import order from "@/static/img/order.png";
import order2 from "@/static/img/order2.png";
import avatar from "@/static/img/avatar.png";
import avatar2 from "@/static/img/avatar2.png";
import TicketCard from "./TicketCard.vue";
import mitter from "../../utils/mitter.js";

import { ref } from "vue";
import typeStore from "../store/typeStore.js";

let showBottom = ref(false);
let store = typeStore();
const loading = ref(false);
const finished = ref(true);
let activeIndex = ref(0);
let tabs = ref(["待使用(1)", "未支付(1)", "已完成(23)"]);

const { type } = defineProps(["type"]);


function queryOrder() {
  showBottom.value = true;
}

defineExpose({
  queryOrder,
});

mitter.on("queryOrder", () => {
  showBottom.value = true;
});

// const onLoad = () => {
//       // 异步更新数据
//       // setTimeout 仅做示例，真实场景中一般为 ajax 请求
//       setTimeout(() => {
//         for (let i = 0; i < 3; i++) {
//           list.value.push(list.value.length + 1);
//         }

//         // 加载状态结束
//         loading.value = false;

//         // 数据全部加载完成
//         if (list.value.length >= 40) {
//           finished.value = true;
//         }
//       }, 1000);
//     };

function closePop() {
  store.type = '2';
  showBottom.value = false;
}
</script>
<style scoped lang="scss">
.header {
  display: flex;
  position: fixed;
  top: 0;
  width: 100%;
  margin-top: 30rpx;
  align-items: center;
  justify-content: center;
  z-index: 100;

  .content {
    width: 90%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    img {
      width: 225.82rpx;
      height: 62rpx;
    }
    .left {
      display: flex;
      align-items: center;
      width: 35vw;
      justify-content: space-between;
      & > :nth-child(2) {
        width: 60.06rpx;
        height: 59.62rpx;
        margin-left: 20rpx;
      }
      .orderbtn {
        width: 190rpx;
        height: 60rpx;
        border-radius: 30.24rpx;
        border: 1px solid #d0dceb;
        opacity: 0.7;
        display: flex;
        justify-content: center;
        align-items: center;

        &:active {
          span {
            color: #a0b3ca !important;
          }
        }

        img {
          width: 24.44rpx;
          height: 28.8rpx;
        }
        & > :nth-child(2) {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 24rpx;
          color: #ffffff;
          line-height: 24rpx;
          text-align: center;
          font-style: normal;
          margin-left: 5px;
        }
      }
    }
  }
}
.bottom {
  width: 750rpx;
  height: 92rpx;
  // background: #000000;
  opacity: 0.6;
  position: fixed;
  bottom: 0;
  display: flex;
  justify-content: center;
  z-index: 100;
  .content {
    width: 90%;
    display: flex;
    align-items: center;
    & > :nth-child(1) {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 28rpx;
      color: #bdbebe;
      line-height: 36rpx;
      text-align: center;
      font-style: normal;
    }
    img {
      width: 44rpx;
      height: 44rpx;
      margin: 0 10px;
    }
    & > :nth-child(3) {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 28rpx;
      color: #ffffff;
      line-height: 36rpx;
      text-align: center;
      font-style: normal;
    }
  }
}

.order-container {
  // width: 750rpx;
  overflow: hidden;

  background: #f7f8f9;
  .content {
    display: flex;
    flex-direction: column;

    .tab-container {
      height: 180rpx;
      background: #ffffff;
      box-shadow: 0rpx 2rpx 0rpx 0rpx #d9dde1;
      border-radius: 40rpx 40rpx 0rpx 0rpx;
      padding: 15px;
      display: flex;
      flex-direction: column;
      position: relative;
      z-index: 1000;
      .closeimg {
        position: absolute;
        right: 38rpx;
        bottom: 58rpx;
        width: 48rpx;
        height: 48rpx;
      }

      .tab {
        width: 600rpx;
        height: 80rpx;
        background: #ffffff;
        border-radius: 8rpx 0rpx 0rpx 8rpx;
        border: 2rpx solid #d9d9d9;
        margin-top: 20px;
        display: flex;
        .tab-item {
          width: 200rpx;
          background: #ffffff;
          border-radius: 8rpx 0rpx 0rpx 8rpx;
          border: 2rpx solid #d9d9d9;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }

      .title {
        width: 176rpx;
        height: 44rpx;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 44rpx;
        color: #000000;
        line-height: 44rpx;
        text-align: left;
        font-style: normal;
      }
    }

    .body-container {
      height: 950rpx;
      padding: 15px;
      overflow-y: auto;
    }
  }
}
.active {
  border: 2rpx solid #005ff9 !important ;
  span {
    color: #005ff9;
  }
}
</style>
